package adsf.adminisadsf.gugedianzishichang.fragment;


import java.util.HashMap;

/**
 * Created by administrator on 17/5/9.
 */

//生成frgment的工厂
public class FragmentFactory
{

    //为了提高性能
    private static HashMap<Integer,BaseFragment> mFragment = new HashMap<>();

    public static BaseFragment createFragment(int id)
    {
        //先从集合中取如果没有在创建
        BaseFragment fragment = mFragment.get(id);

        if (fragment == null) {
            switch (id) {
                case 0:
                    fragment = new HomeFragment();
                    break;
                case 1:
                    fragment = new AppFragment();
                    break;
                case 2:
                    fragment = new GameFragment();
                    break;
                case 3:
                    fragment = new SubjectFragment();
                    break;
                case 4:
                    fragment = new RecommendFragment();
                    break;
                case 5:
                    fragment = new CategoryFragment();
                    break;
                case 6:
                    fragment = new HotFragment();
                    break;

                default:
                    break;
            }

            mFragment.put(id,fragment);
        }

        return fragment;
    }
}
